<?php
namespace app\model;

class ChatMessage extends BaseModel
{
    protected $name = 'chat_messages';

    // 自动时间戳
    protected $autoWriteTimestamp = true;

    // 类型转换
    protected $type = [
        'created_at' => 'integer',
        'updated_at' => 'integer',
        'delete_time' => 'integer',
        'message_type' => 'integer'
    ];

    // 消息类型常量
    const TYPE_TEXT = 1;    // 文本消息
    const TYPE_IMAGE = 2;   // 图片消息
    const TYPE_FILE = 3;    // 文件消息
    const TYPE_AUDIO = 4;   // 音频消息
    const TYPE_VIDEO = 5;   // 视频消息

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 关联会话
     */
    public function session()
    {
        return $this->belongsTo(ChatSession::class, 'session_id');
    }
} 